<?php

namespace App\Domain\ChannelBusiness\Dao;

use App\Domain\ChannelBusiness\Models\ChannelBusinessModel;

class ChannelBusinessDao
{
    public function findByName($name)
    {
        return ChannelBusinessModel::where('name', $name)->where('state','1')->first();
    }

    public function findById($id)
    {
        return ChannelBusinessModel::where('id', $id)->first();
    }

    public function del($id)
    {
        return ChannelBusinessModel::where('id', $id)->update(['state' => '0']);
    }

    public function findAllName(){
        return ChannelBusinessModel::get();
    }

    /**
     * 创建渠道商
     * @param $params
     * @return ChannelBusinessModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return ChannelBusinessModel::create($params);
    }

    /**
     * 修改渠道商
     * @param ChannelBusinessModel $model
     * @param $param
     * @return ChannelBusinessModel
     */
    public function update(ChannelBusinessModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }
}
